	package edu.wpi.cs509.ui;

import edu.wpi.cs509.common.exceptions.IllegalMove;
import edu.wpi.cs509.common.exceptions.InitialPlacementError;
import edu.wpi.cs509.common.exceptions.InvalidLocation;
import edu.wpi.cs509.common.exceptions.PieceNotFound;
import edu.wpi.cs509.common.exceptions.ServerUnreachable;
import edu.wpi.cs509.representation.Location;
import edu.wpi.cs509.representation.PlayerPiece;
import edu.wpi.cs509.representation.TeamColor;
import edu.wpi.cs509.ui.intfc.GameInterface;

public class GameWrapper implements GameInterface {

	private GameInterface clientGame;
	
	public GameWrapper( GameInterface clientGame ) {
		this.clientGame = clientGame;
	}
	
	@Override
	public void placePiece(Location loc, PlayerPiece piece) throws IllegalMove,
			InvalidLocation, ServerUnreachable {
		clientGame.placePiece(loc, piece);
	}

	@Override
	public void removePiece(Location loc) throws IllegalMove, InvalidLocation, ServerUnreachable {
		clientGame.removePiece(loc);
	}

	@Override
	public void ready() throws InitialPlacementError, ServerUnreachable {
		clientGame.ready();
	}

	@Override
	public void move(Location from, Location to) throws IllegalMove, ServerUnreachable {
		clientGame.move(from, to);
	}

	@Override
	public void quit() throws ServerUnreachable {
		System.out.println("UI: clientGame.quit() called!");
		clientGame.quit();
	}

	@Override
	public boolean isSquareEmpty(Location loc) throws InvalidLocation {
		return clientGame.isSquareEmpty(loc);
	}

	@Override
	public PlayerPiece getPiece(Location loc) throws PieceNotFound {
		return clientGame.getPiece(loc);
	}

	@Override
	public long getGameID() {
		return clientGame.getGameID();
	}

	@Override
	public String getMyName() {
		String name = clientGame.getMyName();
		
		if (name == null) {
			System.out.println("ERROR:: Game Interface 'String getMyName()' returned null !!");
			name = "FIXME";
		}
		
		return name;
	}

	@Override
	public String getOpponentName() {
		return clientGame.getOpponentName();
	}

	@Override
	public TeamColor getMyColor() {
		TeamColor color = clientGame.getMyColor();
		
		if (color == null) {
			System.out.println("ERROR:: Game Interface 'TeamColor getMyColor()' returned null !!");
			System.out.println("ERROR:: Returning TeamColor.RED ");
			color = TeamColor.RED;
		}
		
		return color;
	}

	@Override
	public TeamColor getOpponentColor() {
		TeamColor color = clientGame.getOpponentColor();
		
		if (color == null) {
			System.out.println("ERROR:: Game Interface 'TeamColor getOpponentColor()' returned null !!");
			System.out.println("ERROR:: Returning TeamColor.BLUE ");
			color = TeamColor.BLUE;
		}
		
		return color;
	}

	@Override
	public boolean isJoinable() {
		return clientGame.isJoinable();
	}

	@Override
	public boolean isObservable() {
		return clientGame.isObservable();
	}

	@Override
	public boolean obfuscatePieces() {
		return clientGame.obfuscatePieces();
	}

	@Override
	public boolean gameIsObserver() {
		return clientGame.gameIsObserver();
	}
}
